package com.example.service.impl;

import com.example.dao.FlightMapper;
import com.example.dao.ManagerMapper;
import com.example.entity.City;
import com.example.entity.Flight;
import com.example.entity.FlightDetail;
import com.example.entity.Ticket;
import com.example.service.FlightService;
import org.apache.ibatis.session.SqlSession;

import java.util.Date;
import java.util.List;

public class FlightServiceImpl implements FlightService {
    private final FlightMapper mapper;
    private final SqlSession sqlSession;

    public FlightServiceImpl(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
        this.mapper = sqlSession.getMapper(FlightMapper.class);
    }
    public void commit() {
        sqlSession.commit();
    }
    public void rollback() {
        sqlSession.rollback();
    }

    @Override
    public List<String> getTop4ArrivalCities() {
        return mapper.getTop4ArrivalCities();
    }
    @Override
    public List<String> getTop4DepartureCities() {
        return mapper.getTop4DepartureCities();
    }
    @Override
    public Flight searchCheapestFlight(String departure, String destination, String departureDate){
        return mapper.searchCheapestFlight(departure, destination, departureDate);
    }
    @Override
    public int isCityExist(String city) {
        String result = mapper.isCityExist(city);
        if(result == null) return 0;
        return Integer.parseInt(result);
    }
    @Override
    public City getNearCity(String city) {
        return mapper.getNearCity(city);
    }
    @Override
    public List<Flight> searchFlights(String departure, String destination, Date departureDate) {
        return mapper.searchFlights(departure, destination, departureDate);
    }
    @Override
    public List<FlightDetail> searchFlightDetails(String departure, String destination, Date departureDate) {
        return mapper.searchFlightDetails(departure, destination, departureDate);
    }

    @Override
    public int addACityPoint(String city) {
        return mapper.addACityPoint(city);
    }

    @Override
    public int addDCityPoint(String city) {
        return mapper.addDCityPoint(city);
    }
    //添加航班

    @Override
    public int addPlane(String p_model, String p_airline, String build_date, String WiFi, int capacity, int economy_seat, int business_seat, int first_seat) {
        return mapper.addPlane(p_model, p_airline, build_date, WiFi, capacity, economy_seat, business_seat, first_seat);
    }
    @Override
    public int getLastPlaneId() {
        return mapper.getLastPlaneId();
    }
    @Override
    public int addFlight(String f_model, int plane_id, String f_airline, String departure_airport, String arrival_airport, String departure_city, String arrival_city, String departure_date, String departure_time, String arrival_date, String arrival_time, double distance, double economy_price, double business_price, double first_price, int baggage_limit, String meal, String meal_money, String gate) {
        return mapper.addFlight(f_model, plane_id, f_airline, departure_airport, arrival_airport, departure_city, arrival_city, departure_date, departure_time, arrival_date, arrival_time, distance, economy_price, business_price, first_price, baggage_limit, meal, meal_money, gate);
    }
    @Override
    public int getLastFlightId() {
        return mapper.getLastFlightId();
    }
    @Override
    public int addFlightStatus(int f_id, String date, String captain, String assistant_captain, String chief_attendant, int flight_crew_num, int economy_space, int first_space, int business_space, String status) {
        return mapper.addFlightStatus(f_id, date, captain, assistant_captain, chief_attendant, flight_crew_num, economy_space, first_space, business_space, status);
    }
    //改签

    @Override
    public Ticket getTicketById(int t_id) {
        return mapper.getTicketById(t_id);
    }
    @Override
    public Flight getFlightById(int f_id){
        return mapper.getFlightById(f_id);
    }

}
